from urllib.parse import quote_plus

import requests
import pandas as pd
from sqlalchemy import create_engine


def mysql_config():
    user = 'live_data'
    password = quote_plus('CJMg2tsHg7sj6bo0UTKq0a4T!fPDpJ')
    # passwd ='merchantsasd123!@%&'
    host = 'rm-bp17r99475xuauk63yo.mysql.rds.aliyuncs.com'
    # port1 ='3306'
    dbname2 = 'live_data'
    engine2 = create_engine(f"mysql+pymysql://{user}:{password}@{host}:3306/{dbname2}?charset=utf8mb4")
    return engine2

"""批量调用"""
def piliang_refer():

    data2 = pd.read_sql("select * from live_data.xhs_user_error_login where win='B'",mysql_config())
    data_list = [data2.loc[i].to_dict() for i in data2.index.values]
    for i in data_list:

        data = {
            "env":0,
            "biztype":1,
            "xhs_account":i["xhs_account"]
        }

        url = "http://127.0.0.1:5006/xhs/unbind/DeleteUser"

        data = requests.post(url,json=data)
        print(data.text)
    return "批量调用成功"

piliang_refer()

"""单独调用"""
def delete_user_refer():
    data = {
        "env": 0,
        "biztype": 1,
        "xhs_account": '5412188641'
    }

    url = "http://127.0.0.1:5006/xhs/unbind/DeleteUser"

    data = requests.post(url, json=data)
    print(data.text)


# print(delete_user_refer())